package com.htudata.a2service;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.htudata.common.service.DataEhcacheService;
import com.htudata.common.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class A2Service {

  @Autowired
  private DataEhcacheService dataEhcacheService;
  
  @Autowired
  private TokenService tokenService;
  
  @Value("${a2_info_url}")
  private String a2InfoUrl;
  
  public String validateToken(String a2) throws Exception {
    return validateToken(null, null, a2);
  }
  
  public String validateToken(HttpServletRequest request, HttpServletResponse response, String a2) throws Exception {
    try {
      if (a2 == null)
        return this.tokenService.validateToken(request, response, null); 
      return this.tokenService.validateToken(request, response, this.tokenService
          .validateToken(a2, this.a2InfoUrl));
    } catch (Exception e) {
       throw e;
    } 
  }
}
